package com.gcloud.configuracion;

import android.app.Activity;
import android.os.Bundle;
import com.gcloud.*;  
import com.gcloud.librerias.*;
import com.gcloud.login.LoginValidator;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.example.gcode.*;  
import com.example.gcode.R.drawable;
public class Cuentas extends Activity implements OnItemSelectedListener{
	
	Button button1, button2, button3;
	
	private static String KEY_SUCCESS = "success";
	private static String KEY_ERROR = "error";
	private static String KEY_ERROR_MSG = "error_msg";
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cuentas_layout);
		
		Spinner spinner = (Spinner) findViewById(R.id.spinner);
		spinner.setOnItemSelectedListener(this);
		
		// Spinner Drop down elements
        List<String> servicios = new ArrayList<String>();
        servicios.add("Agregar nueva cuenta");
        servicios.add("Google Drive");
        servicios.add("Dropbox");
        
        // Creating adapter for spinner
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, servicios);
 
        // Drop down layout style - list view with radio button
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
 
        // attaching data adapter to spinner
        spinner.setAdapter(dataAdapter);
		
		
		button2 = (Button) findViewById(R.id.button2);
		button3 = (Button) findViewById(R.id.button3);
		
		button2.setOnClickListener(new View.OnClickListener() {			
			
			@Override
			public void onClick(View view){
				String usuario = "1";
				
				UserFunctions userFunction = new UserFunctions();
				userFunction.obtenerCuentas(usuario);
			}
		});
		
		button3.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String id_cuenta = "1";
				
				UserFunctions userFunction = new UserFunctions();
				userFunction.eliminarCuenta(id_cuenta);
				
				
			}
		});
	}
	
	@Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        // On selecting a spinner item
        String item = parent.getItemAtPosition(position).toString();
 
        // Showing selected spinner item
        Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();
 
    }
 
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
 
    }
	
}
